// ==UserScript==
// @name         tower sign
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://crazydefenseheroes.com/earn-tower
// @icon         https://www.google.com/s2/favicons?domain=crazydefenseheroes.com
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        none
// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

//初始化 添加控制面板
function step0_initial() {
    var $panel = $(` <div class="output">
        <p id="timer"></p>
      </div>`);
   

    addGlobalStyle(`.output{
        padding:14px;
        height: 40px;
        width: 150px;
        background-color: #000;
        position:absolute;
        z-index:1000;
        top: 20px;
        left: 0px;
        position:fixed;
    }
    .output p{
        font-size:14px;
        margin-left: 5px;
    }
    .cs-button{
        border: 2px solid #4785a6;
        padding: 3px;
        width: 120px;
        border-radius: 5px;
    }
    .cs-button:hover{
       background-color:#e9e9e9;
    }
    .auto-button{
        background-color:#4785a6;
        color:white;
        margin-bottom:8px;
    }
    .auto-button:hover{
        color:#222222;
    }
    `);
    var $e = $("body").append($panel);
}

(function () {
    'use strict';
    let t = 0;
    
    var intervalId = null;
    var waitTime = 3;
    var varCounter = 0;
    var varName = function(){
        var $notClaimed = $(".CalendarDay_not_claimed__7PM8Q");
        varCounter++;
        $("#timer").text(varCounter + " times")
        if($notClaimed.length>0){
            $(".CalendarDay_not_claimed__7PM8Q").trigger("click");;
            clearInterval(intervalId);
        }   
    };

    $(document).ready(function () {
        step0_initial(); 
        //初始化 添加了状态栏，样式表  

        intervalId = setInterval(varName,waitTime * 1000);

    });


})();
